package app.common;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class ContextListener implements ServletContextListener {

	public ContextListener() {
		System.out.println("ContextListener");
	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		System.out.println("ContextListener.contextInitialized");
		InputStream inputStream = this.getClass().getClassLoader()
				.getResourceAsStream("META-INF/config.properties");
		Properties properties = new Properties();
		try {
			properties.load(inputStream);
		} catch (IOException e) {
			e.printStackTrace();
		}
		String propValue = properties.getProperty("test");
		System.out.println("Property value is: " + propValue);
		String appDir = arg0.getServletContext().getRealPath("/");
		System.out.println("appDir=" + appDir);
		GlobalConstants.listCurrent();
		DatabaseManager.init();
	}

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		System.out.println("ContextListener.contextDestroyed");
		DatabaseManager.shutdownDB();
	}

}
